package game;

import sengine.Character;
import sengine.Sprite;
import sengine.Texture;

/**
 * Represents any kind of flying projectile. The default implementation may
 * assume that the projectile will have inertial effects as well.
 *
 * @author twoodf5611
 */
public abstract class Bullet extends Sprite implements Weapon {
    public final int startx, starty;
    public Bullet(int x, int y, int width, int height) {
        super(x, y, width, height);
        startx = x;
        starty = y;
        setVx(200);
        setPhysType(PhysicsType.BULLET); // For now, need to figure out gravity
        setTexture(Texture.loadTexture("bulletbill.jpg"));
    }

    @Override
    public void collideTarget(Character target) {
        damage(target);
        rmSelf();
    }

    public abstract int getDamage();

    protected void damage(Character target) {
        target.changeHealth(-getDamage());
    }

    @Override
    public void update(long time) {
        super.update(time);
        if (Math.hypot(getX()-startx, getY()-starty)>600) {
            rmSelf();
        }
    }
}
